<%@page import="java.sql.ResultSet"%>
<%@ page import="java.util.Date" language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page session="true" %>
<%@ page contentType="text/html; charset=UTF-8" import="com.mysql.jdbc.*"%>
<%@ page contentType="text/html; charset=UTF-8" import="java.sql.Connection"%>
<%@ page contentType="text/html; charset=UTF-8" import="java.sql.DriverManager"%>
<%@ page contentType="text/html; charset=UTF-8" import="java.sql.Statement"%>
<%@ page contentType="text/html; charset=UTF-8" import="java.util.*"%>
<%@ page contentType="text/html; charset=UTF-8" import="java.util.ArrayList"%>
<% 
	session = request.getSession(true);
	String strId = (String)session.getAttribute("id");
	if(strId == null){
		response.sendRedirect("login.jsp");
	}
	
	Connection con = null;
    Statement stmt = null;
    String strRet = new String();
 	int ret = 0;
 	
    try
    {
    	Class.forName("com.mysql.jdbc.Driver").newInstance(); 
		Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mimo" ,"root" ,"d0o9o84");
        
        stmt = conn.createStatement();
        
        ResultSet result = stmt.executeQuery("select * from projectrels where userId='" + strId + "';");

		ArrayList<String> prjs = new ArrayList<String>();
		
		while(result.next()){
        	String strProjectId = result.getString("projectId");

        	if(strProjectId == null){
        		strProjectId = "";
        	}
        	
        	prjs.add(strProjectId);
		}
%>

<html>
	<head>
		<script type="text/javascript" src="js/jquery-1.6.2.js"></script>
		<script type="text/javascript">
			
			var svgns = 'http://www.w3.org/2000/svg';
			var xlinkns = "http://www.w3.org/1999/xlink";
			var aWindow;
			
			var bCreate = false;
			
			printProjectList = function(){
				
			}
		
			printCreateProject = function(){
			}
			
			mouseOver = function(obj){
				obj.setAttributeNS(null, 'fill', '#FFF');
			}
			
			mouseOut = function(obj){
				obj.setAttributeNS(null, 'fill', '#F8F8F8');
			}
			
			resize = function(){
			}
			
			
			
			init = function(){
				resize();
				displayCreateProject(false);
			}
			
			var windowCreateProject = function(){
				
				var x = (eleBody.offsetWidth / 2) - 150;
				var y = (eleBody.offsetHeight / (10 / 7)) - 100;
				
				eleRootSvg.setAttributeNS(null,'style', 'cursor:hand;');
			}
			
			
			toggleProject = function(){
				if(bCreate == true){
					bCreate = false;
					
					displayCreateProject(false);
				}else{
					bCreate = true;
					
					displayCreateProject(true);
				}
			}
			
			displayCreateProject = function(bShow){
				if(bShow == true){
					$(".fld_createProject").show();
				}else{
					$(".fld_createProject").hide();
				}
			}
			
			goProjectPage = function(url){
				document.location = url;
			}
			

			
		</script>
	</head>
	<body id="eleBody" onload="init();" onresize="resize();">
		<div>
		<%
		String strMsg = request.getParameter("msg");
		if(strMsg != null){
			out.println(strMsg);
		}
		%>
		</div>
		<table width="100%" height="100%">
		<tr>
		<td style="align:center;" >
		<div align="center">

			<%
			for(int iter = 0; iter < prjs.size(); iter++){
	        	String strProjectId = prjs.get(iter);
	        	//String strProjectName = result.getString("projectName");
	        	//String strProjectDescript = result.getString("projectDescript");
	        	
	        	
	        	result = stmt.executeQuery("select * from project where projectId='" + strProjectId + "';");
	        	

	        	if(result.next() == true){
		        	String strProjectName = result.getString("projectName");
		        	String strProjectLeader = result.getString("leader");
		        	String strProjectDescription = result.getString("description");
		        	
	        	%>
	        	
			<div style="position:relative;">
			<svg style="cursor:hand;" onclick="goProjectPage('./projectNavigate.jsp?projectId=<%=strProjectId%>');" onmouseover="mouseOver(this);" onmouseout="mouseOut(this);" 
				fill="#FDFDFD" width="300px" height="110px" xmlns="http://www.w3.org/2000/svg" >
				<rect rx="5" ry="5"  width="100%" height="100%" stroke="#DDD" stroke-width="1px" />
				<image preserveAspectRatio="none" xlink:href="img/emptyProject/plus.gif" x="20" y="20" width="60px" height="70px" />
				<text x="110" y="25" font-size="12" fill="#000"><tspan style="font-family:'돋움';"><%=strProjectId%></tspan></text>
				<text x="110" y="55" font-size="12" fill="#000"><%=strProjectName%></text>
			</svg>
			</div>
	        	
	        	<%
	        	}
	        }
			%>
			<hr width="310px"/>
			<div style="position:relative;">
			<svg style="cursor:hand;" id="eleRootSvg" onclick="displayCreateProject(true);" onmouseover="mouseOver(this);" onmouseout="mouseOut(this);" 
				fill="#FDFDFD" width="300px" height="110px" xmlns="http://www.w3.org/2000/svg" >
				<rect rx="5" ry="5"  width="100%" height="100%" stroke="#DDD" stroke-width="1px" />
				<image preserveAspectRatio="none" xlink:href="img/emptyProject/plus.gif" x="20" y="20" width="60px" height="70px" />
				<text x="110" y="25" font-size="12" fill="#000"><tspan style="font-family:'돋움';">Mimo 접속을 환영합니다.</tspan></text>
				<text x="110" y="55" font-size="12" fill="#000">여기를 클릭하시면 프로젝트를</text>
				<text x="110" y="75" font-size="12" fill="#000">생성 할 수 있습니다.</text>
			</svg>
			</div>
			
		</div>
		</td>
		</tr>
		</table>
		
		
		<svg class="fld_createProject" style="position:absolute;cursor:hand;left:0;top:0;" 
			fill="rgba(100, 100, 100, 0.2)" x="0%" y="0%" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" >
			<rect x="0" y="0" width="100%" height="100%" />
		</svg>
		
		<table class="fld_createProject" style="position:absolute;cursor:hand;left:0;top:0;"  width="100%" height="100%" >
			<tr>
				<td align="center">
					<table style="background-color:#DDAAAA;">
						<tr>
							<td>
								<span style="font-family:'돋움';font-size:9pt;">
									<form action="createProject.jsp" method="post" enctype="multipart/form-data">
									프로젝트 ID &#160;&#160;&#160;:&#160;&#160; <input name="projectId" type="text" style="width:300pt;" /> <br/>
									프로젝트 Title :&#160;&#160; <input name="projectName" type="text" style="width:300pt;" /> <br/>
									프로젝트 설명 :&#160; <TEXTAREA name="projectDescript" ></TEXTAREA> <br/>
									
									프로젝트 아이콘 : <input name="projectIcon" type="file" /> <br/>
									<span algn="right">
									<input type="submit" value="프로젝트 생성" />
									<input type="button" value="cancle" onclick="displayCreateProject(false);" /> <br/> 
									</span>
									</form>
								</span>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</body>
</html>

<%
        result.close();
        stmt.close();
        conn.close();
    }
    catch( Exception ex )
    {
    	ret = -1;
    }
%>